package site.wtcc.originalfavor.func.exception;

import lombok.Getter;

/**
 * 自定义异常
 *
 * @author hexiaodou
 * @date 2022/09/05 15:50:39
 */
@Getter
public class RestException extends RuntimeException {

    private static final long serialVersionUID = 7566528438429367681L;

    private final String errorCode;
    private final ResponseCode responseCode;
    public RestException(ResponseCode error) {
        super(error.getMessage());
        this.errorCode = error.name();
        responseCode = error;
    }
    public RestException(String error) {
        super(error);
        this.errorCode = ResponseCode.ERROR.name();
        responseCode = ResponseCode.ERROR;
    }

    public RestException(ResponseCode error, Throwable cause) {
        super(error.getMessage(), cause);
        this.errorCode = error.name();
        responseCode = error;
    }

    public RestException(ResponseCode error, String errorMsg) {
        super(errorMsg);
        this.errorCode = error.name();
        responseCode = error;
    }

    public RestException(ResponseCode error, String format, Object... args) {
        super(String.format(format, args));
        this.errorCode = error.name();
        responseCode = error;
    }

    public RestException(ResponseCode error, String errorMsg, Throwable cause) {
        super(errorMsg, cause);
        this.errorCode = error.name();
        responseCode = error;
    }

    @Override
    public String toString() {
        return "[" + errorCode + "] " + super.toString();
    }

}
